package it.koutifaris.travianmap.view.serversview;

import it.koutifaris.travianmap.R;
import it.koutifaris.travianmap.command.CommandOnMenuItemClickListener;
import it.koutifaris.travianmap.context.HasApplicationContex;
import it.koutifaris.travianmap.view.commandlistview.ListViewOnItemClickListener;
import it.koutifaris.travianmap.view.commandlistview.ListViewOnLongClickListener;
import android.view.Menu;
import android.widget.ListView;

public class ServersViewController extends HasApplicationContex {

	private final ServersView view;

	public ServersViewController() {
		view = new ServersViewImpl();
	}

	void show() {
		getActivity().setContentView(R.layout.servers);
		configure();
	}

	void prepareMenu(Menu menu) {
		view.setAddServerMenuItemClickHandler(
				menu,
				new CommandOnMenuItemClickListener(new AddServerCommand()));
	}

	private void configure() {
		getListView().setAdapter(new ServersAdapter(getTravianMapContext(), view));
		getListView().setOnItemClickListener(new ListViewOnItemClickListener());
		getListView().setOnItemLongClickListener(new ListViewOnLongClickListener());
	}

	private ListView getListView() {
		return view.getListView();
	}

}
